<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="xl" title="资源详情" hide-footer scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit text-left m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_title">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题</label>
                        </div>
                        <div class="col-md-4">
                            <input class="form-control placeholder-no-fix" type="text" disabled ref="resources_title" placeholder="请输入" v-model="oauthResourcesForm.resources_title"/>
                        </div>
                    </div>
                    
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_parentid">上级资源</label>
                        </div>
                        <div class="col-md-4">
                            <input class="form-control placeholder-no-fix" type="hidden" v-model="oauthResourcesForm.resources_parentid" />
                            <div class="input-group">
                                <input type="text" class="form-control" disabled v-model="oauthResourcesForm.resources_parentidTitle_">
                            </div>
                        </div>                        
                    </div>
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_iconCls">字体图标</label>
                        </div>
                        <div class="col-md-4">
                            <input class="form-control placeholder-no-fix" disabled type="text" placeholder="请输入"  v-model="oauthResourcesForm.resources_iconCls"/>
                        </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="info">老版本菜单图标，如la la-plus</b-badge>  
                        </div>                       
                    </div>
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label">所属模块</label>
                        </div>
                        <div class="col-md-2">
                            <el-select disabled v-model="oauthResourcesForm.sysModuleId" placeholder="请选择">
                                <el-option
                                v-for="item in sysModulesList"
                                :key="item.id"
                                :label="`${item.sySname}-----${item.name}`"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="danger">菜单所属指定平台下模块</b-badge>  
                        </div>
                    </div>  
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_sys">平台资源</label>
                        </div>
                        <div class="col-md-2">
                            <el-select maxlength="20" disabled v-model="oauthResourcesForm.resources_sys" placeholder="请选择">
                                <el-option
                                    v-for="item in [{value:0,label:'否'},{value:1,label:'是'}]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="warning">如果为平台资源则不在权限分配中展示</b-badge>  
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_leaf">叶子节点</label>
                        </div>
                        <div class="col-md-2">
                            <el-select maxlength="20" disabled v-model="oauthResourcesForm.resources_leaf" placeholder="请选择">
                                <el-option
                                    v-for="item in [{value:0,label:'是'},{value:1,label:'否'}]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态</label>
                        </div>
                        <div class="col-md-2">
                            <el-select maxlength="20" disabled v-model="oauthResourcesForm.resources_status" placeholder="请选择">
                                <el-option
                                    v-for="item in [{value:0,label:'可用'},{value:1,label:'禁用'}]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_sort">排&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;序</label>
                        </div>
                        <div class="col-md-2">
                            <el-input-number 
                            v-model="oauthResourcesForm.resources_sort" 
                            maxlength="10" 
                            disabled
                            style="width:100px;" 
                            controls-position="right"
                             :min="0" 
                             :max="9999">
                            </el-input-number>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_url">访问地址</label>
                        </div>
                        <div class="col-md-6">
                            <input class="form-control placeholder-no-fix" type="text" disabled placeholder="请输入"  v-model="oauthResourcesForm.resources_url"/>
                        </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="dark">老版本访问地址，如/index.html</b-badge>  
                        </div>
                    </div>        
                    <div class="form-group m-form__group row">
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_sort">组件路由</label>
                        </div>
                        <div class="col-md-4">
                            <input class="form-control placeholder-no-fix" type="text" disabled placeholder="请输入" v-model="oauthResourcesForm.component_router"/>
                        </div>     
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="primary">新版本VUE请求路由</b-badge>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">  
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">组件图标</label>
                        </div>
                        <div class="col-md-4">
                            <b-input-group>
                                <input class="form-control placeholder-no-fix" disabled type="text" placeholder="请输入" v-model="oauthResourcesForm.component_icon"/>
                                <b-input-group-append>
                                <b-button variant="outline-secondary" v-if="null != oauthResourcesForm.component_icon && '' != oauthResourcesForm.component_icon">
                                    <i class="icon-xl " :class="oauthResourcesForm.component_icon"></i>
                                </b-button>
                                </b-input-group-append>
                            </b-input-group>
                        </div>     
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="secondary">新版本VUE请求路由所访问的资源文件</b-badge>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">                        
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">组件地址</label>
                        </div>
                        <div class="col-md-6">
                            <input class="form-control placeholder-no-fix" type="text" disabled placeholder="请输入" v-model="oauthResourcesForm.component_router_to"/>
                        </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="success">新版本VUE菜单所使用图标</b-badge>                            
                        </div>
                    </div>
                    <div class="form-group m-form__group row">                        
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">跳转方式</label>
                        </div>
                        <div class="col-md-2">
                            <el-select maxlength="20" disabled v-model="oauthResourcesForm.component_jump_type" placeholder="请选择">
                                <el-option
                                    v-for="item in [{value:0,label:'站内'},{value:1,label:'站外'},{value:2,label:'iframe'}]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                         </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="info">浏览器是否需要打开新的标签页</b-badge>                            
                        </div>
                    </div>
                    <div class="form-group m-form__group row">                        
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">是否隐藏</label>
                        </div>
                        <div class="col-md-2">
                            <el-select maxlength="20" disabled v-model="oauthResourcesForm.component_hide_menu" placeholder="请选择">
                                <el-option
                                    v-for="item in [{value:0,label:'否'},{value:1,label:'是'}]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                         </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="info">左侧导航栏是否需要展示该菜单</b-badge>                            
                        </div>
                    </div>
                    <div class="form-group m-form__group row">                        
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">是否打开新页面</label>
                        </div>
                        <div class="col-md-2">
                            <el-select maxlength="20" disabled v-model="oauthResourcesForm.component_open_new_page" placeholder="请选择">
                                <el-option
                                    v-for="item in [{value:0,label:'否'},{value:1,label:'是'}]"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                         </div>
                        <div class="col-md-2">
                            <b-badge class="mr-1" variant="warning">浏览器是否需要打开新的标签页</b-badge>                            
                        </div>
                    </div>
                    <div class="form-group m-form__group row">                        
                        <div class="col-md-2">
                            <label class="col-form-label" jEhcLang="resources_status">激活展开样式</label>
                        </div>
                        <div class="col-md-5">
                            <input class="form-control placeholder-no-fix" disabled type="text" placeholder="请输入" v-model="oauthResourcesForm.component_open_style"/>
                         </div>
                        <div class="col-md-2">
                            <b-badge class="mr-4" variant="danger">注意存在子菜单时候展开菜单后是否激活样式，新版本VUE使用</b-badge>                            
                        </div>
                    </div>         
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
        </template>
        <OauthResourcesTreeSelect ref="oauthResourcesTreeSelectRef" @change="setResourcesSelect"></OauthResourcesTreeSelect>
    </b-modal>        
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js"; 
import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
import OauthResourcesTreeSelect from "@/view/oauth/oauth-resources/oauth-resources-tree-select.vue";

export default {
    data(){
        return {    
            oauthResourcesForm:{
                id:"",
                name: "",
                url:"",
                parentId:"0",
                parentName:'一级资源',
                leaf:0,
                iconCls:"",
                isSys:0,
                sysModuleId:"",
                sort:"",
                status:0,
                componentRouter:"",
                componentRouterTo:"",
                componentIcon:"",
                componentJumpType:0,
                componentHideMenu:0,
                componentOpenNewPage:0,
                componentOpenStyle:"",
            },
            sysModulesList:[]
        }
    },
    components: {
        OauthResourcesTreeSelect,
    },
    watch: {
    },
    mounted() {
        this.initSysModulesList();
    },
    methods: {
        setResourcesSelect(data){
            this.oauthResourcesForm.parentId = data.id;        
            if(data.name == null || data.name ==""){
                this.oauthResourcesForm.parentName="一级资源"
            }else{
                this.oauthResourcesForm.parentName=data.name
            }   
        },
        showResourcesSelect(){
            this.$refs.oauthResourcesTreeSelectRef.showModal(this.oauthResourcesForm.id);
        },        
        showModal(id) {
            this.restForm();
            this.$refs['my-modal'].show();
            this.getOauthResourcesDetail(id);
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        restForm(){
            //重置
            Object.assign(this.$data.oauthResourcesForm, this.$options.data().oauthResourcesForm);
        },
        initSysModulesList(){
            let params = {};
            apiUtil.post(process.env.VUE_APP_OAUTH_API+"/oauthSysModules/listAll", params).then(({ data }) => {
                this.sysModulesList = data.data;
            });
        },
        getOauthResourcesDetail(id){
            apiUtil.get(process.env.VUE_APP_OAUTH_API+"/oauthResources/get/"+id).then(({ data }) => {
                this.oauthResourcesForm = data.data;        
                if(data.data.parentName == null || data.data.parentName ==""){
                    this.oauthResourcesForm.parentName="一级资源"
                }              
            });
        }
   }
}
</script>